package com.monkeyboy.rabbitmq.advanced_features.limit;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
	/**
	 * 作用： Return Listener
	 * 
	 * @Author:Gavin
	 * @time:2018年10月30日
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		// 1.创建连接工厂
		ConnectionFactory connectionFactory = new ConnectionFactory();
		connectionFactory.setHost("localhost");
		connectionFactory.setPort(5672);
		connectionFactory.setVirtualHost("/myproject");
		connectionFactory.setUsername("Gavin");
		connectionFactory.setPassword("123456");
		// 2.获取到连接对象Connection
		Connection connection = connectionFactory.newConnection();

		// 3.通过Connection创建一个新的Channel
		Channel channel = connection.createChannel();

		// 4.制定我们的消息投递模式：消息的确认模式
		channel.confirmSelect();

		String exchangeName = "test_qos_exchange";
		String routingKey = "qos.save";
		for (int i = 0; i < 3; i++) {
			// 发送消息
			channel.basicPublish(exchangeName, routingKey, true, null, "Hello qos msg".getBytes());
		}
		channel.close();
		connection.close();
	}
}
